package com.example.zjx8969.myapplication.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import android.util.Log;

import com.example.zjx8969.myapplication.cache.CacheFileManager;
import com.example.zjx8969.myapplication.net.InitBean;

import threads.PriorityThreadPool;
import threads.RunnablePriority;

public class InitalViewModel extends ViewModel {
    MutableLiveData<InitBean> liveData = new MutableLiveData<>();

    public LiveData<InitBean> getData() {
        return liveData;
    }

    public InitalViewModel() {
        PriorityThreadPool.getInstance().execute(RunnablePriority.LOW, new Runnable() {
            @Override
            public void run() {
                InitBean initBean = CacheFileManager.getInstance().cacheManager.readContent("jGmrobJyKtE", InitBean.class);
                liveData.postValue(initBean);
            }
        });
    }


    public void changeData() {
        InitBean value = liveData.getValue();
        if(value==null) return;
        String defaultSite = value.defaultSite;
        value.defaultSite = "https://m.yhouse.com/";
        Log.e("tag", String.format("changeData before:%s after:%s", defaultSite, value.defaultSite));
        liveData.setValue(value);

    }


}
